$(document).ready(function () {
	$('.comment_anchor').css('opacity', 0.35);
	
	$('.comment_anchor').mouseover(function () {
		$(this).css('opacity', 1);
	});
	
	$('.comment_anchor').mouseout(function () {
		$(this).css('opacity', 0.35);
	});
	
	$('#photos_move_back').height ($('#view_photo').height());
	$('#photos_move_forward').height ($('#view_photo').height());
});

function setAlbumPreview (albumId, photoId) {
	$.ajax ({
		url:  baseURI + '/photos/ajax_set_album_preview/' + albumId + '/' + photoId + '?scode=' + scode,
		dataType: 'xml',
		type: 'get',
		error: function () { new Error ('Произошла ошибка!');  },
		success: function (xml) {
			var result = $(xml).find('result').text();
			
			if (result == '0') {
				new Error ('Произошла ошибка!');
			} else {
				$('#album_preview_controller_' + photoId).html('');
			}
		}
	});
}

function votePhoto (photoId, mark) {
	if (mark != 1) {
		mark = 0;
	}
	
	$.ajax ({
		url:  baseURI + '/photos/ajax_vote_photo/' + photoId + '/' + mark + '?scode=' + scode,
		dataType: 'xml',
		type: 'get',
		error: function () { new Error ('Произошла ошибка!');  },
		success: function (xml) {
			var result = $(xml).find('result').text();
			
			if (result == '0') {
				new Error ('Произошла ошибка!');
			} else {
				new Message ('Ваш голос учтен!');
				var rating = $(xml).find('rating').text();
				if (rating > 0) {
					$('#photo_rating_'+photoId).text ('+' + rating);
				} else {
					$('#photo_rating_'+photoId).text (rating);
				}
				
				if (mark == 1) {
					$('#photo_vote_plus_'+photoId).find('img').attr ('src',  baseURI + '/images/post-voted-plus.png');
					$('#photo_vote_minus_'+photoId).find('img').attr ('src',  baseURI + '/images/post-vote-minus-cant.png');
				} else {
					$('#photo_vote_plus_'+photoId).find('img').attr ('src',  baseURI + '/images/post-vote-plus-cant.png');
					$('#photo_vote_minus_'+photoId).find('img').attr ('src',  baseURI + '/images/post-voted-minus.png');
				}
				
				document.getElementById('photo_vote_plus_'+photoId).onclick = function () {return false;};
				document.getElementById('photo_vote_minus_'+photoId).onclick = function () {return false;};
				
				$('#photo_vote_plus_'+photoId).click (function () { new Error ('Повторное голосование запрещено!') });
				$('#photo_vote_minus_'+photoId).click (function () { new Error ('Повторное голосование запрещено!') });
			}
		}
	});
}